package admin

import database "hft/Database"

type Role struct {
	database.Base
	LoginPage string     `json:"login_page"` //登录页
	PID       uint       `json:"pid,omitempty"`
	RoleName  string     `json:"roleName,omitempty" gorm:"not null;foreignKey:PID;references:ID;constraint:OnDelete:CASCADE;OnUpdate:CASCADE"`
	Link      string     `json:"link,omitempty" gorm:"type:varchar(255);size:255;index"`
	Accounts  []*Account `json:"accounts,omitempty" gorm:"foreignKey:RoleId;constraint:OnDelete:CASCADE;OnUpdate:NO ACTION"`
	Roles     []*Role    `json:"roles,omitempty" gorm:"foreignKey:PID;constraint:OnDelete:CASCADE;OnUpdate:CASCADE"`
	Routes    []*Route   `json:"routes" gorm:"many2many:_routes_roles;foreignKey:ID;JoinForeignKey:RoleId;references:ID;JoinReferences:RouteId;constraint:OnDelete:CASCADE;OnUpdate:CASCADE"`
	Apis      []*Api     `json:"apis" gorm:"many2many:_roles_apis;constraint:OnDelete:CASCADE,OnUpdate:NO ACTION"`
}

func (Role) TableName() string {
	return database.TableNameFormat("roles")
}
